﻿using BonjourQuotation.ObjectModel.BusinessData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BonjourQuotation.DataAccess.Repositories;
using BonjourQuotation.ObjectModel.ErrorData;
using BonjourQuotation.UI.Models.PartialModel;
using BonjourQuotation.ObjectModel.LoggerData;

namespace BonjourQuotation.UI.ServiceManagers
{
    public class QuotationManager
    {
        private readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public string test()
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.test();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public string GetQuotationQuotaID(int param, List<string> UserRegions)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.GetQuotationQuotaID(param, UserRegions).ToString();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public ErrorBInfo MakeQuotaToId(string id)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.MakeQuotaToId(Convert.ToInt32(id));
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationDetailsBData GetQuotationBDataByQuotaId(string QuotaId, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotationDetailsBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.GetQuotationBDataByQuotaId(id, UserName);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public List<QuotaLookupBData> LoadQuotaLookupData(string ByRef, string Keyword)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.LoadQuotaLookupData(ByRef, Keyword);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaHotelGridBData LoadQuotaHotelGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaHotelGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaHotelGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaLunchDinnerGridBData LoadQuotaLunchDinnerGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaLunchDinnerGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaLunchDinnerGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaEntranceGridBData LoadQuotaEntranceGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaEntranceGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaEntranceGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaMiscGridBData LoadQuotaMiscGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaMiscGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaMiscGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaBusGridBData LoadQuotaBusGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaBusGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaBusGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaGuideGridBData LoadQuotaGuideGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaGuideGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaGuideGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaCostPriceGridBData LoadQuotaCostPriceGrid(string QuotaId, string FreeCalc)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaCostPriceGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.LoadQuotaCostPriceGrid(id, FreeCalc);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaCostPriceGridBData CalcQuotaCostPriceGrid(int QuotaId, QuotaCostPriceGridBData Data, string FreeCalcType)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaCostPriceGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.CalcQuotaCostPriceGrid(id, Data, FreeCalcType);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public Dictionary<int, string> FindKeywordInEntity(string PropName, string keyword)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.FindKeywordInEntity(PropName, keyword);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaVendorContractsBData LoadVendorContract(int VendorID, int SeasonID)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.LoadVendorContract(VendorID, SeasonID);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        #region New, Save, Save As
        public QuotationDetailsBData NewQuotationBData(string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.NewQuotationBData(UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public ErrorBInfo SaveQuotaDetails(QuotationDetailsBData QuotaDetails)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.SaveQuotaDetails(QuotaDetails);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotationDetailsBData SaveAsQuotationBDataByQuotaId(string QuotaId, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotationDetailsBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.SaveAsQuotationBDataByQuotaId(id, UserName);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
 
        #endregion

        #region Tabs Line
        public QuotaHotelGridBData NewLineQuotaHotelGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaHotelGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.NewLineQuotaHotelGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaHotelGridBData InsertLineQuotaHotelGrid(string QuotaId, string LineNum)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaHotelGridBData result = null;
                int id = 0;
                int line = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNum);
                    result = proxy.InsertLineQuotaHotelGrid(id, line);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaHotelGridBData UpdateQuotaHotelGrid(List<QuotaHotelGridRowBData> Rows, bool IsNewLine, bool IsInsert, int InsertRow)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaHotelGridBData result = null;
                result = proxy.UpdateQuotaHotelGrid(Rows, IsNewLine, IsInsert, InsertRow);
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaLunchDinnerGridBData InsertLineQuotaLunchDinnerGrid(string QuotaId, string LineNum)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaLunchDinnerGridBData result = null;
                int id = 0;
                int line = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNum);
                    result = proxy.InsertLineQuotaLunchDinnerGrid(id, line);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
       
        public QuotaLunchDinnerGridBData NewLineQuotaLunchDinnerGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaLunchDinnerGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.NewLineQuotaLunchDinnerGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaLunchDinnerGridBData UpdateQuotaLunchDinnerGrid(List<QuotaLunchDinnerGridRowBData> Rows)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaLunchDinnerGridBData result = null;
                result = proxy.UpdateQuotaLunchDinnerGrid(Rows);
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaEntranceGridBData InsertLineQuotaEntranceGrid(string QuotaId, string LineNum)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaEntranceGridBData result = null;
                int id = 0;
                int line = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNum);
                    result = proxy.InsertLineQuotaEntranceGrid(id, line);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaEntranceGridBData NewLineQuotaEntranceGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaEntranceGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.NewLineQuotaEntranceGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaEntranceGridBData UpdateQuotaEntranceGrid(List<QuotaEntranceGridRowBData> Rows)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaEntranceGridBData result = null;
                result = proxy.UpdateQuotaEntranceGrid(Rows);
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaMiscGridBData InsertLineQuotaMiscGrid(string QuotaId, string LineNum)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaMiscGridBData result = null;
                int id = 0;
                int line = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNum);
                    result = proxy.InsertLineQuotaMiscGrid(id, line);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaMiscGridBData NewLineQuotaMiscGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaMiscGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.NewLineQuotaMiscGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaMiscGridBData UpdateQuotaMiscGrid(List<QuotaMiscGridRowBData> Rows)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaMiscGridBData result = null;
                result = proxy.UpdateQuotaMiscGrid(Rows);
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaBusGridBData InsertLineQuotaBusGrid(string QuotaId, string LineNum)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaBusGridBData result = null;
                int id = 0;
                int line = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNum);
                    result = proxy.InsertLineQuotaBusGrid(id, line);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaBusGridBData NewLineQuotaBusGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaBusGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.NewLineQuotaBusGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaBusGridBData UpdateQuotaBusGrid(List<QuotaBusGridRowBData> Rows)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaBusGridBData result = null;
                result = proxy.UpdateQuotaBusGrid(Rows);
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaGuideGridBData InsertLineQuotaGuideGrid(string QuotaId, string LineNum)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaGuideGridBData result = null;
                int id = 0;
                int line = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNum);
                    result = proxy.InsertLineQuotaGuideGrid(id, line);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        public QuotaGuideGridBData NewLineQuotaGuideGrid(string QuotaId)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaGuideGridBData result = null;
                int id = 0;
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    result = proxy.NewLineQuotaGuideGrid(id);
                }
                catch
                {
                }
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotaGuideGridBData UpdateQuotaGuideGrid(List<QuotaGuideGridRowBData> Rows)
        {
            try
            {
                var proxy = new QuotationRepository();
                QuotaGuideGridBData result = null;
                result = proxy.UpdateQuotaGuideGrid(Rows);
                return result;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }

        #endregion

        #region Delete
        public ErrorBInfo RemoveFromGrid(int ItmID ,string QuotaId, string LineNo, string TabName)
        {
            try
            {
                int id = 0, line = 0;
                var proxy = new QuotationRepository();
                try
                {
                    id = Convert.ToInt32(QuotaId);
                    line = Convert.ToInt32(LineNo);
                }
                catch
                {
                }
                return proxy.RemoveFromGrid(ItmID, id, line, TabName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        #endregion
        #region upload
        public ErrorBInfo UploadProposal(string QuotaId, string PropFile)
        {
            try
            {
                int id = 0;
                var proxy = new QuotationRepository();
                try
                {
                    id = Convert.ToInt32(QuotaId);
                }
                catch
                {
                }
                return proxy.UploadProposal(id, PropFile);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        #endregion
        #region Advanced Search
        public QuotationAdvancedSearchBData QuotationAdvancedSearchBData()
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.QuotationAdvancedSearchBData();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public List<QuotaAdvancedSearchGridBData> QuotationAdvancedSearch(QuotationAdvancedSearchBData data)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.QuotationAdvancedSearch(data);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        #endregion

        #region Create Group
        public int CreateNonGirGroup()
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.CreateNonGirGroup();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return 0;
            }  
        }
        public ErrorBInfo SaveNonGirGroup(QuotationGroupBData Data)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.SaveNonGirGroup(Data);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationGirGroupGridBData CreateGirNonGirGroup(int QuotaID, bool Gir, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.CreateGirNonGirGroup(QuotaID, Gir, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationGirGroupGridBData NewGirNonGirGroup(QuotationGirGroupGridBData Data, bool Gir, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.NewGirNonGirGroup(Data, Gir, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationGirGroupGridBData NewGirNonGirGroupPush(int GroupID, bool Gir, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.NewGirNonGirGroupPushOperation(GroupID, Gir, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationGirGroupGridBData NewGirGroupCustomer(QuotationGirGroupGridBData Data, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.NewGirGroupCustomer(Data, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationGirGroupGridBData SaveGirNonGirGroup(QuotationGirGroupGridBData Data, bool Gir, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.SaveGirNonGirGroup(Data, Gir, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        public QuotationGirGroupGridBData SaveGirGroupInvoice(QuotationGirGroupGridBData Data, string UserName)
        {
            try
            {
                var proxy = new QuotationRepository();
                return proxy.SaveGirGroupInvoice(Data, UserName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToMessageAndCompleteStacktrace());
                return null;
            }  
        }
        #endregion
    }
}